package com.yf.dmp.util;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

//全局配置类--配置跨域请求
@Configuration
public class WebConfig  {

    public WebMvcConfigurer corsConfigurer() { return new WebMvcConfigurerAdapter() {
        @Override
        public void addCorsMappings(CorsRegistry registry) {
            /**
             * 1.域访问路径
             * 2.请求来源
             * 3.访问方法
             * 4.运行携带，例如token等
             * 5.最大请求时间
             * */
            registry.addMapping("/**")
                    .allowedOrigins("http://localhost:8089", "null")
                    .allowedMethods("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS", "TRACE")
                    .allowCredentials(true)
                    .maxAge(3600);
        }
    };
    }
}
